home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Franz PD / Franz PD Disk #334 (1994-06)(Rhein-Sieg-Soft).zip / Franz PD Disk #334 (1994-06)(Rhein-Sieg-Soft).adf / ASo-Tools / Sources / FileCheck.c < prev    next >
C/C++ Source or Header  |  1994-04-03  |  4KB  |  147 lines

  1. /*  FileCheck.c
  2.  
  3.     Usage: FileCheck <Path>
  4.  
  5.     Function: FileCheck reads ALL files in <Path> and sub-directories.
  6.         It is designed to find out whether there are faults
  7.         in the file-structure of the OFS on disk
  8.         (These can't be found by DiskCopy for there is no
  9.         trackdisk-fault, but Checksum-Errors produced by OFS).    */
  10.  
  11. #include <exec/libraries.h>
  12. #include <exec/memory.h>
  13. #include <exec/types.h>
  14. #include <dos/dos.h>
  15. #include <dos/exall.h>
  16. #include <dos/dostags.h>
  17. #include <ctype.h>
  18. #include <clib/exec_protos.h>
  19. #include <clib/dos_protos.h>
  20. #include <stdio.h>
  21. #include <string.h>
  22. #include <stdlib.h>
  23.  
  24. #define READBUFFSIZE (488*512/8)    /* das kleinste gemeinsame Vielfache
  25.                        von 512 und 488, den Blockgrößen
  26.                        von altem FS und FFS */
  27.  
  28. APTR ReadBuffer;
  29. BOOL abort;
  30.  
  31. BOOL CheckBreak(void)
  32. {
  33.     if(SetSignal(0,SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C)
  34.     {
  35.     printf("^C\n");
  36.     abort=TRUE;
  37.     }
  38.     return(abort);
  39. }
  40.  
  41. void Check(STRPTR name, long size)
  42. {
  43.     register BPTR FH;
  44.     register long toget;
  45.     long gotten, really_read;
  46.  
  47.     printf("\r%s  [%ld]\233K", name, size); fflush(stdout);
  48.     FH=Open(name,MODE_OLDFILE);
  49.     if(FH==NULL)    { printf(" - Open-Error !\n"); return; }
  50.     for(toget=gotten=0;gotten<size;gotten+=toget)
  51.     {
  52.     toget=size-gotten;
  53.     if(toget>READBUFFSIZE)  toget=READBUFFSIZE;
  54.     really_read=Read(FH,ReadBuffer,toget);
  55.     if(really_read!=toget)
  56.         {
  57.         printf(" - Read-Error near position %ld\n",gotten+really_read);
  58.         break;
  59.         }
  60.     if(CheckBreak())    break;
  61.     }
  62.     Close(FH);
  63. }
  64.  
  65. void tree(STRPTR fullname)
  66. {
  67.     struct FileInfoBlock *eintrag;
  68.     BPTR lock;
  69.     char *newfullname, *to_append;
  70.     short newfn_len=strlen(fullname) + sizeof(eintrag->fib_FileName) + 2;
  71.  
  72.     if(!(lock=Lock(fullname,ACCESS_READ)))
  73.     {
  74.     printf("Error: couldn't lock %s\n", fullname);
  75.     return;
  76.     }
  77.     if(eintrag=(struct FileInfoBlock *)
  78.     AllocMem(sizeof(struct FileInfoBlock),MEMF_CLEAR))
  79.     {
  80.     if(Examine(lock,eintrag))
  81.         {
  82.         if(eintrag->fib_DirEntryType>0)
  83.         {
  84.         if(newfullname=AllocMem(newfn_len, MEMF_CLEAR) )
  85.             {
  86.             strcpy(newfullname,fullname);
  87.             if(fullname[0] && fullname[strlen(fullname)-1]!=':')
  88.             strcat(newfullname,"/");
  89.             to_append=newfullname+strlen(newfullname);
  90.             ExNext(lock,eintrag);
  91.             while(IoErr()!=ERROR_NO_MORE_ENTRIES && !CheckBreak())
  92.             {
  93.             strcpy(to_append,eintrag->fib_FileName);
  94.             if(eintrag->fib_DirEntryType<=0)
  95.                  {
  96.                  if(eintrag->fib_Protection & FIBF_READ)
  97.                   printf("\rFile %s is read protected\n",
  98.                      newfullname);
  99.                  else Check(newfullname, eintrag->fib_Size);
  100.                  }
  101.             else tree(newfullname);
  102.             ExNext(lock,eintrag);
  103.             }
  104.             FreeMem(newfullname, newfn_len);
  105.             }
  106.         else printf("no memory for full filename\n");
  107.         }
  108.         }
  109.     else printf("Error in Examine()'ing %s\n", fullname);
  110.     FreeMem(eintrag, sizeof(struct FileInfoBlock));
  111.     }
  112.     else printf("Error: can't allocate a FIB\n");
  113.     UnLock(lock);
  114. }
  115.  
  116. int main(short argc, STRPTR argv[])
  117. {
  118.     BPTR OrgCD, BaseDir;
  119.  
  120.     if(argc!=2)
  121.     {
  122.     printf("Usage: %s <path>\n",argv[0]);
  123.     return(RETURN_ERROR);
  124.     }
  125.     abort=FALSE;
  126.     if(!(ReadBuffer=AllocMem(READBUFFSIZE,MEMF_PUBLIC)))
  127.     {
  128.     printf("Error: couldn't allocate %ld Bytes of Buffer\n",
  129.            READBUFFSIZE);
  130.     return(RETURN_ERROR);
  131.     }
  132.  
  133.     if((BaseDir=Lock(argv[1], ACCESS_READ))==NULL)
  134.     printf("Error: couldn't lock %s\n", argv[1]);
  135.     else{
  136.     OrgCD=CurrentDir(BaseDir);
  137.     tree("");
  138.     CurrentDir(OrgCD);
  139.     UnLock(BaseDir);
  140.     printf("\r\233K");
  141.     fflush(stdout);
  142.     }
  143.  
  144.     FreeMem(ReadBuffer,READBUFFSIZE);
  145.     return(RETURN_OK);
  146. }
  147.